package com.aiti.lulian.controller.newCard;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.newCard.CardEnterpriseMaterialDto;
import com.aiti.lulian.entity.newCard.CardEnterpriseMaterial;
import com.aiti.lulian.service.CardEnterpriseMaterialService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/new-card/enterprise-material")
public class CardEnterpriseMaterialController extends WebController {

    @Autowired
    private CardEnterpriseMaterialService cardEnterpriseMaterialService;

    @ApiOperation("新增或更新物料")
    @PostMapping
    public Message addOrUpdateEnterpriseMaterial(@RequestBody CardEnterpriseMaterialDto dto) {
        return cardEnterpriseMaterialService.addOrUpdateEnterpriseMaterial(dto);
    }

    @ApiOperation("查询物料列表")
    @GetMapping("/page")
    public Message getEnterpriseMaterialPage(CardEnterpriseMaterialDto dto) {
        Page<CardEnterpriseMaterial> page = startPage(dto.getPageNum(), dto.getPageSize());
        List<CardEnterpriseMaterial> list = cardEnterpriseMaterialService.getEnterpriseMaterialPage(dto, page);
        return Message.success(getPageResult(list, dto.getPageNum(), dto.getPageSize(), page.getTotal()));
    }

    @ApiOperation("查询物料详情")
    @GetMapping("/{baseId}")
    public Message getEnterpriseMaterialDetails(@PathVariable("baseId") String baseId) {
        return Message.success(cardEnterpriseMaterialService.getById(baseId));
    }

    @ApiOperation("删除物料")
    @DeleteMapping("/{baseId}")
    public Message deleteEnterpriseMaterial(@PathVariable("baseId") String baseId) {
        cardEnterpriseMaterialService.removeById(baseId);
        return Message.success();
    }
}
